package com.meichis.yndms.room.dao;

import androidx.room.*;

import com.meichis.yndms.model.Picture;

import java.util.List;


@Dao
public interface PictureDao {
    @Query("SELECT * FROM Picture")
    List<Picture> findAll();

    @Query("SELECT * FROM Picture WHERE Guid=:guid")
    Picture find(String guid);

    @Query("SELECT * FROM Picture WHERE Guid IN(:guid)")
    List<Picture> find(String... guid);

    @Query("SELECT * FROM Picture WHERE IsUpload=:isUpload")
    List<Picture> find(int isUpload);

    @Query("SELECT * FROM Picture WHERE RelateType=:relateType and IsUpload=:isUpload and RelateID=:relateID")
    List<Picture> find(int relateType, int isUpload, int relateID);

    @Query("SELECT * FROM Picture WHERE (RelateType in (1,2,3) or RelateID>0) and IsUpload=0")
    List<Picture> findUpLoadPicture();

    @Query("DELETE FROM Picture")
    int deleteAll();

    @Query("DELETE FROM Picture WHERE Guid IN(:guid)")
    int delete(String... guid);

    @Query("DELETE FROM Picture WHERE RelateType =:RelateType")
    int delete(int RelateType);

    @Delete
    int delete(Picture... Pictures);

    @Delete
    int delete(List<Picture> pictures);

    @Update
    int update(Picture... Pictures);

    @Query("UPDATE Picture SET IsUpload=:newIsUpload WHERE IsUpload=:oldIsUpload")
    int update(int oldIsUpload, int newIsUpload);

    @Query("UPDATE Picture SET RelateID=:relateID WHERE VisitGuid=:visitGuid")
    int update(int relateID, String visitGuid);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long[] insert(List<Picture> list);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long[] insert(Picture... Pictures);

    @Query("SELECT COUNT(*) FROM Picture WHERE (RelateType in (1,2,3) or RelateID>0) and IsUpload=0")
    int countUpLoadPicture();

    @Query("SELECT (SELECT COUNT(*) FROM Picture WHERE RelateID>0 AND IsUpload<>1 )")
    int getNeedUploadPicCount();

    @Query("SELECT * FROM Picture WHERE VisitGuid =:visitGuid")
    List<Picture> findPicByVisitGuid(String visitGuid);
}
